using namespace std;
#include<iostream>
#include<vector>


class Solution {
public:
    void duplicateZeros(vector<int>& arr)
    {
        int pre = 0, cur = 0;
        int n = arr.size();
        while (pre < n)
        {
            int end = n - 1;
            if (arr[pre] == 0)
            {
                while (end > pre)
                {
                    arr[end] = arr[end - 1];
                    end--;
                }
                if (pre <= n - 2)
                {
                    cur = pre + 1;
                }
                arr[cur] = arr[pre];
                pre++;
                if (pre >= n)
                {
                    break;
                }
            }
            pre++;
        }
    }
};